package org.matchit.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;

public class CompositeListConverter<S, T> implements Converter<S, List<T>> {
    private final List<Converter<S, T>> converters = new ArrayList<Converter<S, T>>();

    public CompositeListConverter<S, T> element(Converter<S, T> converter) {
        converters.add(converter);
        return this;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<T> convert(S source) {
        List<T> list = new ArrayList<T>();
        for (Converter<S, T> converter : converters) {
            list.add(converter.convert(source));
        }
        return list;
    }

}
